package com.hunan.api.catv.action.news.pgc;

/**
 * @author jiang zhuan
 * @version 1.0
 * @description 描述
 * @date 2020/9/23 0023
 * @package com.hunan.api.catv.action.news.pgc
 * @company 湖南有线
 */

import com.hunan.api.catv.action.BaseAction;
import com.hunan.api.catv.annotation.MemberAuth;
import com.hunan.api.catv.common.Api;
import com.hunan.api.catv.entity.Result;
import com.hunan.api.catv.service.biz.pgc.PgcNewsBiz;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;

/**
 * pgc短视频接口
 */
@RestController
@RequestMapping(Api.pgc)
@Validated
public class PgcNewsAction extends BaseAction {

    @Autowired
    private PgcNewsBiz pgcNewsBiz;

    @GetMapping(value = {"/list/{activityId}"})
    public Result list(@PathVariable @NotNull(message = "activityId required") Integer activityId, int pageNum, HttpServletRequest request) {
        return buildOK(pgcNewsBiz.newsList(activityId, pageNum, getPageSize(request), getMemberIdV2(request)), "");
    }

    @MemberAuth
    @PostMapping("/update/praise/{pgcId}/{type}")
    public Result updatePraiseCount(@PathVariable @NotNull(message = "pgcId required") String pgcId, @PathVariable @Pattern(regexp = "[01]", message = "type [0 or 1] required") String type, HttpServletRequest request) {
        return buildOK(pgcNewsBiz.updatePraiseCount(pgcId, getMemberIdV2(request), type), "");
    }

}
